<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改需求</title>
<base href="<%=basePath%>" />
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" href="<%=basePath%>/js/uploadify/css/uploadify.css" type="text/css"></link>
<link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
<script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/uploadify/jquery.uploadify-3.1.min.js"></script>
<script language="JavaScript" type="text/javascript" src="<%=basePath%>js/my97/WdatePicker.js" defer="defer"></script>
<style type="text/css">
fieldset,legend,form,table,tr,td,textarea {margin: 0;padding: 0}
form label {font-weight: bold;}
table {margin: 10px 10px;}
td {line-height: 25px;}
input[type="text"] {width: 250px;}
input[type="password"] {width: 250px;}
input[type="textarea"] {width: 250px;}
.divlist {float: left;height: 100%;width: 60%;}
.divcomment {float: left;height: 100%;width: 40%;}
.word{line-height: 120%;word-break:break-all}
</style>

<script type="text/javascript">
	  var reqId = null;  
	  $(document).ready(function(){
		  
		     $.ajaxSetup ({ cache:false,async: false });
			 // 拒绝或归档-------------------------------------------------------------------
			 $("#statusSub").click(function(){
				  if(isEmpty($("#status").val())) { 
					  alert("状态不能为空！");
					  return false;
			      }
				  else{
					  if($("#status").val()!= 'refused'){
					    if(isEmpty($("#perStaTime").val())){alert("预期开始时间不能为空！"); return false;}
					    if(isEmpty($("#perEndTime").val())){alert("结束时间不能为空！"); return false;}
					    if(isEmpty($("#reason").val())) {alert("变更理由不能为空！");  return false;}
					    $.post("<%=basePath%>depreq/edit.do", {perEndTime:$("#perEndTime").val(),perStaTime:$("#perStaTime").val(),id:$("#id").val(),status:$("#status").val(),reason:$("#reason").val()}, function(data) {
							var result = $.parseJSON(data);
							if(result.code == 1) {
								alert("状态修改成功！");
							} else {
								alert(result.msg);
							}
					   });
					  }
					  else
					  {
						  if(isEmpty($("#reason").val())) {alert("变更理由不能为空！");  return false;}
						  $.post("<%=basePath%>depreq/edit.do", {id:$("#id").val(),status:$("#status").val(),reason:$("#reason").val()}, function(data) {
								var result = $.parseJSON(data);
								if(result.code == 1) {
									alert("状态修改成功！");
								} else {
									alert(result.msg);
								}
						   });
					  }
				  }
				
				 
		     });
			 // 拒绝或归档结束---------------------------------------------------------------
			 
		     //回复信息----------------------------------------------------------------------
			 $('#commentForm').submit(function(){
				    if(isEmpty($("#comment").val()))
				    { 
				    	alert("回复内容不能为空！"); 
				        return false;
				    }
	                $.ajax({
	                    url: "<%=basePath%>myreq/comment.do",   // 提交的页面
	                    data: $('#commentForm').serialize(),    // 从表单中获取数据
	                    type: "POST",                           // 设置请求类型为"POST"，默认为"GET"
	                    dataType: 'json',
	                    error: function(XMLHttpRequest, textStatus, errorThrown) {
	                          alert(XMLHttpRequest.status);
	                    },
	                    success: function(data) {
	                    	if(data.code == 1) {
	                    		 $("#allComment").prepend(
						    			   "<table style=' width: 83%'>"
						    			 +"   <tr>"
						    			 +"      <td ><label>"+ data.createTime+"</label>"
						    			 +"      &nbsp;&nbsp;&nbsp; <font color='red'>"+$("#usercnname").val()+"</font></td>"
						    			 +"   </tr>"
						    			 +"   <tr>"
						    			 +"      <td class='word' >	<span style='color:#00A;'>"+$("#comment").val()+"</span></td>"
						    			 +"   </tr>"
						    			 +" </table>"
						    	  );
								 $('#comment').val('');
	                        }}
	                    });
	                return false;
	            });
		    
		    //回复信息结束----------------------------------------------------------------------
	   });
	   
	   //返回列表页面
	   function btn_return(){
		    var qs = $("#qs").val();
	    	window.location.href="<%=basePath%>depreq/list.do?" + qs;
	   }
	</script>
</head>
<body>
	<div class="divlist">
	    <!-- 基本信息-------------------------------------------------------------------------->
		<div style="width:98%">
	        <input id="qs" name="qs" type="hidden" value="${qs}" />
			<p id="p_error" style="margin: 10px 10px;">
				<label id="error_label" style="color: red;"></label>
			</p>
			<fieldset>
				<legend>基本信息：</legend>
						<table width="95%">
							<tr>
							
								<td width="19%" ><label>标题：</label> </td>
								<td colspan="3"> 
								   ${req.title}
								</td>
							</tr>
							<tr>
						         <td><label for="status">负责方：</label></td>
								 <td>
						               <c:forEach items="${sList}" var="s" varStatus="status">
										       <c:if test="${req.startStatus == s.value}">
										          ${s.name}
										       </c:if>
									   </c:forEach>
						         </td>        
							</tr>
							<tr>
								<td ><label >发起人：</label></td>
								<td width="40%">
								 ${req.cnName}
								</td>
								<td ><label >当前状态：</label></td>
								<td width="40%">
							       <c:forEach items="${itemList}" var="item" varStatus="status">
								       <c:if test="${req.status == item.value}">
								         ${item.name}
								       </c:if>
								   </c:forEach>
								</td>
							</tr>
							<tr>
								<td><label >发起时间：</label></td>
								<td>
								   <fmt:formatDate value="${req.createTime}" type="both"	dateStyle="medium" timeStyle="medium" />
								</td>
								<td ><label >期望完成时间：</label></td>
								<td>
								   <fmt:formatDate value="${req.expPerTime}" type="both"	dateStyle="medium" timeStyle="medium" /> 
								</td>
							</tr>
							<tr>
								<td><label>需求内容：</label> </td>
								<td colspan="3"> 
								    <textarea name="content" readonly="readonly" id="content" cols="60" rows="8"><c:out value="${req.content}"></c:out></textarea>
								</td>
							</tr>
							<c:forEach items="${attList}" var="att" varStatus="status">
							  <tr>
							    <c:if test="${status.count == 1}">
								   <td><label>相关文件：</label> </td>
								</c:if>
								<c:if test="${status.count!=1}">
								   <td></td>
								</c:if>
								<td colspan="3"> 
								   <a href="<%=basePath%>myreq/download.do?fileName=${att.name}&path=${att.path}">${att.name}</a>
								</td>
							  </tr>
							</c:forEach>
						</table>
			</fieldset>
		</div>
	    <!-- 基本信息结束-------------------------------------------------------------------------->
	    
	    <!-- 处理情况------------------------------------------------------------------------------>
		<div style="width:98%">
			<fieldset>
				<legend>处理情况：</legend>
						<table>
							<tr>
								<td width="13.5%" ><label>开始时间：</label>
								    <input type="hidden" id="id" name="id" value="${req.id}"/>
								    <input type="hidden" id="title" name="title" value="${req.title}"/>
								</td>
								<td >
									<input type="text" id="perStaTime" name="perStaTime" style="width:180px;"  value="${req.perStaTime}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'perEndTime\')}'})"	class="Wdate" />
								    <font color="red">&nbsp;*&nbsp;&nbsp;</font>
								</td>
								<td ><label>结束时间：</label></td>
								<td >
								    <input type="text" id="perEndTime" style="width:180px;"  name="perEndTime" value="${req.perEndTime}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'perStaTime\')}'})" class="Wdate" />
							        <font color="red">&nbsp;*&nbsp;&nbsp;</font>
							    </td>
							</tr>
							<tr>
								<td><label>状态：</label></td>
								<td colspan="3">
								   <select id="status" name="status" style="width:120px;">
								        <c:if test="${req.status =='pending'}">
								             <option value="processing">处理中</option>
								             <option value="refused">拒绝</option>
								        </c:if>
					                    <c:if test="${req.status =='processing'}">
								             <option value="processed">已处理</option>
								        </c:if>
								        <c:if test="${req.status =='processed'}">
								             <option value="processed">已处理</option>
								        </c:if>
								        <c:if test="${req.status =='refused'}">
								             <option value="refused">已拒绝</option>
								        </c:if>
					               </select>
					               <font color="red">（提示：拒绝可以不设预计时间）&nbsp;*&nbsp;&nbsp;</font>               
								</td>
							</tr>
							<tr>
								<td valign="top"><label>变更理由：</label></td>
								<td colspan="3">
								       <c:choose>
								         <c:when test="${req.handedDesc !=null}">
								          <textarea id="reason" name ="reason" rows="8" cols="60"><c:out value="${req.handedDesc}"></c:out></textarea>
								         </c:when>
								         <c:when test="${req.status =='refused' && req.refuseReason !=null}">
								          <textarea id="reason" name ="reason" rows="8" cols="60"><c:out value="${req.refuseReason}"></c:out></textarea>
								         </c:when>
								         
								         <c:otherwise>
								           <textarea id="reason" name ="reason" rows="8" cols="60"></textarea>
								         </c:otherwise>
								       </c:choose>
								       <font color="red">&nbsp;*&nbsp;&nbsp;</font>
								</td>
							</tr>
							<tr>
								<td></td>
								<td colspan="3"> 
									  <input type="button" id="statusSub" value="提交" style="width: 80px;" /> 
									  &nbsp; 
									  <input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width: 80px;" />
								</td>
							</tr>
					</table>
			</fieldset>
		</div>
	</div>
    <!-- 处理情况结束------------------------------------------------------------------------------>
	
	<!-- 交流版 ----------------------------------------------------------------------------------->
	  <div class="divcomment">
		<fieldset >
			<legend>交流板</legend>
		    <form id="commentForm" >
				<table style="width: 85%">
					<tr>
						<td ><textarea name="comment" id="comment" cols="40" rows="5"></textarea></td>
					    <td valign="bottom">
					      <input type="hidden" name="objectId" id="objectId" value="${req.id}">
					      <input type="submit" id="send" name="send" value="发表" />
					      <input type="hidden"  id="usercnname" value="${sessionScope.usercnname}">
					    </td>
					</tr>
				</table>
		    </form>
			<div id="allComment">
			   <c:forEach  items="${comList}" var="com">
					<table>
						<tr>
							<td>
								<label for="project">
								  <fmt:formatDate value="${com.createTime}" type="both"	dateStyle="medium" timeStyle="medium" />
								</label>
								&nbsp;&nbsp;&nbsp;
								<font color="red">${com.userCnname}</font>
							</td>
						
						</tr>
						<tr>
							<td class="word">
								<span style="color:#00A;">${com.content}</span>
							</td>
						</tr>
					</table>
				</c:forEach>
			</div>
		</fieldset>
	</div>
    <!-- 交流版结束 ---------------------------------------------------------------------------------------->
</body>
</html>